home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol06 / 01 / kermit / wnkerm.h < prev    next >
Text File  |  1990-12-31  |  13KB  |  318 lines

  1. /*
  2.  * WNKERM.H
  3.  *
  4.  * Windows Kermit header file
  5.  *
  6.  * Copyright (c) 1990 by
  7.  * William S. Hall
  8.  * 3665 Benton Street, #66
  9.  * Santa Clara, CA 95051
  10.  *
  11.  * This file should be included in one module in
  12.  * the code for the terminal in the following 
  13.  * way in order to declare the Kermit external variables:
  14.  * #if defined(KERMIT)
  15.  * #define KERMITEXTERN
  16.  * #include "wnkerm.h"
  17.  * #endif
  18.  *
  19.  */
  20.  
  21. /* This curious construction allows declaration of
  22.  * Kermit variables only in the module in which
  23.  * KERMITEXTERN is defined
  24.  */
  25. #if !defined(KERMITEXTERN)
  26. #define KERMITEXTERN extern
  27. #endif
  28.  
  29. /*
  30.  * Kermit function declarations
  31.  */
  32. /* from Kermit protocol module */
  33. int wart(void);
  34.  
  35. /* from Kermit function support module wnkfns.c */
  36. void    NEAR    krm_tinit(void);    /* initialize session */
  37. int    NEAR    krm_sinit(void);    /* send init packet */
  38. void    NEAR    krm_err(int ref);    /* respond to error */
  39. void    NEAR    krm_spar(BYTE *data, short len);/* read remote's init params */
  40. char *    NEAR    krm_getnextfile(BOOL first);    /* build incoming packet */
  41. int    NEAR    krm_sfile(void);    /* send file name */
  42. int    NEAR    krm_seot(void);        /* send break packet */
  43. int    NEAR    krm_seof(char *s);    /* send end of file packet */
  44. int    NEAR    krm_sdata(void);    /* send file data */
  45. BOOL    NEAR    krm_rclose(BOOL);    /* close a file */
  46. void    NEAR    krm_tend(int code);    /* end session */
  47. void    NEAR    krm_checkcnx(void);    /* check for session cancellation */
  48. int    NEAR    krm_rpar(BYTE data[]);    /* prepare local init packet */
  49. /* encode data before transmission */
  50. int    NEAR    krm_encode(BYTE *outbuf, BYTE *inbuf, int maxlen, int *len);
  51. void    NEAR    krm_ack(short len, BYTE * str); /* ack a packet */
  52. BOOL    NEAR    krm_rcvfil(void);    /* receive a file name */
  53. BOOL    NEAR    krm_rcvdata(void);    /* receive data */
  54. int    NEAR    krm_rpack(void);    /* read a packet and return type */
  55. void    NEAR    krm_resend(void);    /* resend a packet */
  56. /* create a pseudo packet for handling internal errors */
  57. void    NEAR    krmCreatePseudoPacket(char type, short state, int msgnum);
  58. void    FAR    krmShowMessage(int msgnum);    /* show a message to user */
  59. BOOL    FAR    krmWndCommand(HWND hWnd, WORD mode); /* Kermit menu function */
  60. void    FAR    krmPaint(HWND hWnd, HDC hDC);    /* paint terminal's icon */
  61. void    NEAR    krm_savename(void);    /* show remote's name for file */
  62. void    NEAR    krmFlushQue(void);    /* flush the input and output queues */
  63. int    FAR    krmShutdown(void);    /* respond to terminal shutdown */
  64. /* handle packet timeouts */
  65. void FAR PASCAL krmDoTimeout(HWND hWnd,unsigned message,short event,DWORD time);
  66.  
  67. /* from Kermit dialog box routines module wnkmsc.c */
  68. /* open a dialog box */
  69. int  FAR    krmOpenDlgBox(HWND hWnd, FARPROC fpProc, WORD boxnum);
  70. /* show progress of transfers */
  71. BOOL FAR PASCAL krmXferDlgBox(HWND, unsigned, WORD, LONG);
  72. /* cancel session */
  73. BOOL FAR PASCAL krmCancelBoxProc(HWND, unsigned, WORD, LONG);
  74. /* select files for sending */
  75. BOOL FAR PASCAL krmSendFileProc(HWND, unsigned, WORD, LONG);
  76. /* modify protocol parameters */
  77. BOOL FAR PASCAL krmProtocol(HWND hDlg,unsigned message,WORD wParam,LONG lParam);
  78. /* modify inbound and outbound packet parameters */
  79. BOOL FAR PASCAL krmPackets(HWND hDlg,unsigned message,WORD wParam,LONG lParam);
  80.  
  81. /* from Kermit initialization module wnkint.c */
  82. /* start up initialization of Kermit */
  83. BOOL    FAR    krmInit(HWND hWnd, BYTE *bufptr, int *buflen, int *cid);
  84.  
  85. /* macros */
  86. #define tochar(ch)    ((ch) + ' ')    /* convert int to printable char */
  87. #define unchar(ch)    ((ch) - ' ')    /* convert printable char to int */
  88. #define ctl(ch)        ((ch) ^ 64)    /* 'controllify' a char */
  89.  
  90. /* constants and defaults */
  91. #define KRM_MINTIMEOUT        2    /* packet timeout parameters */
  92. #define KRM_MAXTIMEOUT        60
  93. #define KRM_DEFTIMEOUT        5
  94. #define KRM_MINPACKETSIZE    10    /* packet sizes */
  95. #define KRM_MAXPACKETSIZE    94
  96. #define KRM_DEFPACKETSIZE    80
  97. #define KRM_MAXDATALEN        (KRM_MAXPACKETSIZE - 3) /* max data size */
  98. #define KRM_FILEABORT        1    /* file transfer abort flags */
  99. #define KRM_BATCHABORT        2
  100. #define KRM_ERROR_PACKET    0    /* id of error packet */
  101. #define KRM_MAXPADCOUNT        94    /* packet padding paramters */
  102. #define KRM_DEFPADCOUNT        0
  103. #define KRM_DEFPADCHAR        '\000'
  104. #define KRM_DEFTIMER        TRUE    /* default to timer on */
  105. #define KRM_DEFVERBOSE        TRUE    /* show transfer details */
  106. #define KRM_DEFFILEWARN        TRUE    /* warn about duplicate files */
  107. #define KRM_DEFDISCARD        TRUE    /* discard partial files */
  108. #define KRM_DEFBELL        TRUE    /* ring bell after transfer */
  109. #define KRM_DEFBLOCKCHECK    1    /* default block check type */
  110. #define KRM_DEFSENDDELAY    0    /* default delay before first packet */
  111. #define KRM_MAXSENDDELAY    60    /* maximum delay */
  112. #define KRM_DEFRETRYLIMIT    10    /* retry limits */
  113. #define KRM_MAXRETRYLIMIT    63
  114. #define KRM_MINRETRYLIMIT    1
  115. #define KRM_DEFMARK        '\001'    /* default start of packet char */
  116. #define KRM_DEFEOL        '\015'    /* default end of packet char */
  117. #define KRM_DEFQUOTE        '#'    /* default control char quote */
  118. #define KRM_DEFEBQUOTE        '&'    /* default 8-bit char quote */
  119. #define KRM_DEFRPTQUOTE        '~'    /* default repeat char quote */
  120.  
  121. /* menu items */
  122. #define KRM_MENUBASE        10000    /* adjust to avoid menu id conflicts */
  123. #define IDM_KRM_RECEIVE        KRM_MENUBASE
  124. #define IDM_KRM_SEND        KRM_MENUBASE+1
  125. #define IDM_KRM_CANCEL        KRM_MENUBASE+2
  126. #define IDM_KRM_FILEABORT    KRM_MENUBASE+3
  127. #define IDM_KRM_BATCHABORT    KRM_MENUBASE+4
  128. #define IDM_KRM_ERRORABORT    KRM_MENUBASE+5
  129. #define IDM_KRM_PROTOCOL    KRM_MENUBASE+6
  130. #define IDM_KRM_PACKETS        KRM_MENUBASE+7
  131.  
  132. /* strings */
  133. #define KRM_STRINGBASE         10100 /* adjust to avoid string id conflicts */
  134. #define IDS_KRM_TRANSACTION_DONE    KRM_STRINGBASE
  135. #define IDS_KRM_UNKNOWN_PACKET        KRM_STRINGBASE+1
  136. #define IDS_KRM_CANCELLED        KRM_STRINGBASE+2
  137. #define IDS_KRM_TOOMANYRETRIES        KRM_STRINGBASE+3
  138. #define IDS_KRM_FILE_OPEN_ERROR        KRM_STRINGBASE+4
  139. #define IDS_KRM_FILE_READ_ERROR        KRM_STRINGBASE+5
  140. #define IDS_KRM_FILE_WRITE_ERROR    KRM_STRINGBASE+6
  141. #define IDS_KRM_FILE_CLOSE_ERROR    KRM_STRINGBASE+7
  142. #define IDS_KRM_SENDING            KRM_STRINGBASE+8
  143. #define IDS_KRM_SENDINIT_ERROR        KRM_STRINGBASE+9
  144. #define IDS_KRM_SENDFILENAME_ERROR    KRM_STRINGBASE+10
  145. #define IDS_KRM_SENDDATA_ERROR        KRM_STRINGBASE+11
  146. #define IDS_KRM_SENDEOF_ERROR        KRM_STRINGBASE+12
  147. #define IDS_KRM_SENDEOT_ERROR        KRM_STRINGBASE+13
  148. #define IDS_KRM_CANNOTINIT        KRM_STRINGBASE+14
  149. #define IDS_KRM_KERMITMENU        KRM_STRINGBASE+15
  150. #define IDS_KRM_KERMIT            KRM_STRINGBASE+16
  151. #define IDS_KRM_TIMER            KRM_STRINGBASE+17
  152. #define IDS_KRM_FILEWARN        KRM_STRINGBASE+18
  153. #define IDS_KRM_VERBOSE            KRM_STRINGBASE+19
  154. #define IDS_KRM_DISCARD            KRM_STRINGBASE+20
  155. #define IDS_KRM_BELL            KRM_STRINGBASE+21
  156. #define IDS_KRM_BLOCKCHECKTYPE        KRM_STRINGBASE+22
  157. #define IDS_KRM_SENDDELAY        KRM_STRINGBASE+23
  158. #define IDS_KRM_RETRYLIMIT        KRM_STRINGBASE+24
  159. #define IDS_KRM_SENDMARK        KRM_STRINGBASE+25
  160. #define IDS_KRM_RCVMARK            KRM_STRINGBASE+26
  161. #define IDS_KRM_SENDMAXLEN        KRM_STRINGBASE+27
  162. #define IDS_KRM_RCVMAXLEN        KRM_STRINGBASE+28
  163. #define IDS_KRM_SENDTIMEOUT        KRM_STRINGBASE+29
  164. #define IDS_KRM_RCVTIMEOUT        KRM_STRINGBASE+30
  165. #define IDS_KRM_SENDPADCOUNT        KRM_STRINGBASE+31
  166. #define IDS_KRM_RCVPADCOUNT        KRM_STRINGBASE+32
  167. #define IDS_KRM_SENDPADCHAR        KRM_STRINGBASE+33
  168. #define IDS_KRM_RCVPADCHAR        KRM_STRINGBASE+34
  169. #define IDS_KRM_SENDEOL            KRM_STRINGBASE+35
  170. #define IDS_KRM_RCVEOL            KRM_STRINGBASE+36
  171. #define IDS_KRM_SENDQUOTE        KRM_STRINGBASE+37
  172. #define IDS_KRM_RCVQUOTE        KRM_STRINGBASE+38
  173. #define IDS_KRM_QUIT            KRM_STRINGBASE+39
  174.  
  175. /* timer values */
  176. #define KRM_TIMERBASE    10200    /* adjust as needed for timer conflicts */
  177. #define KRM_WAITPACKET    KRM_TIMERBASE    /* SetTimer parameter for timeout */
  178. #define KRM_WAITSEND    KRM_TIMERBASE+1    /* SetTimer parameter for send delay */
  179.  
  180. /* this enumeration type is used to plot the
  181.  * progress of a packet as it is filled
  182.  */
  183. enum PACKETSTATE {PS_START,    /* start accumulating packet data */
  184.           PS_SYNCH,    /* waiting for start of header */
  185.           PS_LEN,    /* waiting for length byte */
  186.           PS_NUM,    /* waiting for packet number */
  187.           PS_TYPE,    /* waiting for packet type */
  188.           PS_DATA,    /* reading data */
  189.           PS_CHK,    /* reading checksum */
  190.           PS_DONE,    /* packet is complete */
  191. };
  192.  
  193. /*
  194.  * KERMITPARAMS
  195.  *
  196.  * This data structure is associated with the Kermit protocol
  197.  * settings dialog box.
  198.  *
  199.  */
  200. typedef struct _KERMITPARAMS {
  201.     BOOL Bell;                /* sound warning bell */
  202.     BOOL Timer;                /* use timer */
  203.     BOOL DiscardPartialFile;        /* discard partial file */
  204.     BOOL FileWarning;            /* rename incoming files if conflict */
  205.     short BlockCheckType;        /* char, word, or CRC block check */
  206.     short SendDelay;            /* delay before sending first packet */
  207.     short RetryLimit;            /* retry attempts before timing out */
  208.     BYTE ebquote;            /* eight bit quote character */
  209.     BYTE rpquote;            /* repeat quote character */
  210.     BOOL verbose;            /* show progress of transfer */
  211. } KERMITPARAMS;
  212.  
  213. /*
  214.  * KRMPACKETPARAMS
  215.  *
  216.  * This data structure is associated with the Kermit packet
  217.  * settings dialog box.
  218.  *
  219.  */
  220. typedef struct _KRMPACKETPARAMS {
  221.     BYTE mark;            /* start of header character */
  222.     short maxpktsize;        /* maximum packet size */
  223.     short timeout;        /* timeout interval */
  224.     short padcount;        /* padding character count */
  225.     BYTE padchar;        /* padding character */
  226.     BYTE eol;            /* end of packet character */
  227.     BYTE quote;            /* control character quote */
  228. } KRMPACKETPARAMS;
  229.  
  230. /* 
  231.  * KERMITDATA
  232.  *
  233.  * This structure contains most of the additional parameters
  234.  * needed by Kermit.
  235.  */
  236. typedef struct _KERMITDATA {
  237.     HWND hWnd;                /* main window handle */
  238.     HANDLE hInst;            /* instance handle */
  239.     BOOL start;                /* start transfer */
  240.     BOOL InTransfer;            /* in transfer */
  241.     WORD mode;                /* mode of transfer - send, receive */
  242.     short bctu;                /* block check type used */
  243.     short bctr;                /* block check type requested */
  244.     short seq;                /* packet sequence number */
  245.     BOOL delay;                /* waiting to send first packet */
  246.     FARPROC fpTimer;            /* farproc pointer to Kermit timer */
  247.     short retries;            /* retries per packet */
  248.     short totalretries;            /* total retries */
  249.     OFSTRUCT fstruct;            /* file structure */
  250.     DWORD bytesmoved;            /* bytes transferred */
  251.     DWORD packetcount;            /* packets exchanged */
  252.     DWORD filesize;            /* size of send file */
  253.     int percentage;            /* percentage of file sent */
  254.     int maxsenddatalen;            /* max send packet data length */
  255.     int hFile;                /* file handle */
  256.     HANDLE hFilelist;            /* handle to send file list */
  257.     char *pFilelist;            /* pointer to send file list */
  258.     char *pFile;            /* pointer to single file */
  259.     FARPROC fpXfer;            /* transfer dialog box farproc */
  260.     HWND hWndXfer;            /* handle to transfer dialog box */
  261.     short abort;            /* abort type; file or group */
  262.     BOOL ebqflag;            /* using eight-bit quoting */
  263.     BOOL rptflag;            /* using run-length encoding */
  264. } KERMITDATA;
  265.  
  266. /*
  267.  * KRMPACKET structure
  268.  *
  269.  * This data structure is used to hold the various fields
  270.  * of a packet received from the remote Kermit.
  271.  *
  272.  */
  273. typedef struct _KRMPACKET {
  274.     short len;                /* length of packet */
  275.     short seq;                /* packet sequence number */
  276.     BYTE type;                /* packet type */
  277.     BYTE data[KRM_MAXDATALEN + 1];    /* packet data */
  278.     char rchksum[3];            /* received checksum bytes */
  279.     short data_count;            /* current data count */
  280.     short chk_count;            /* current checksum data count */
  281.     enum KRMPACKETSTATE state;        /* state of packet decomposition */
  282. } KRMPACKET;
  283.  
  284. /*
  285.  * KRMSENDINIT structure
  286.  * 
  287.  * This structure is used to hold the parameters required
  288.  * to compose outbound packets and to decompose inbound packets.
  289.  *
  290.  */
  291. typedef struct _KRMSENDINIT {
  292.     BYTE mark;            /* start of packet header */
  293.     short maxpktsize;        /* maximum packet size */
  294.     short timeout;        /* how many seconds to wait before timing out */
  295.     short padcount;        /* how much padding to add to a packet */
  296.     BYTE padchar;        /* character used for padding */
  297.     BYTE eol;            /* character denoting end of packet */
  298.     BYTE quote;            /* control code quote character */
  299.     BYTE ebquote;        /* eight bit quote character */
  300.     BYTE rpquote;        /* run length quote character */
  301. } KRMSENDINIT;
  302.  
  303. /* External variables needed by Kermit */
  304. KERMITEXTERN KERMITPARAMS KermParams;   /* protocol dialog box values */
  305. KERMITEXTERN KRMPACKETPARAMS sndparams;    /* outbound packet dialog box values */
  306. KERMITEXTERN KRMPACKETPARAMS rcvparams;    /* inbound packet dialog box values */
  307.  
  308. KERMITEXTERN KRMSENDINIT krm_sndinit;   /* data for making outbound packets */
  309. KERMITEXTERN KRMSENDINIT krm_rcvinit;   /* data for making inbound packets */
  310. KERMITEXTERN KERMITDATA Kermit;        /* most other Kermit data */
  311. KERMITEXTERN KRMPACKET krm_rcvpkt;    /* holds data from incoming packet */
  312.  
  313. KERMITEXTERN BYTE krm_sndpkt[100]; /* Holds an assembled packet to be sent */
  314. KERMITEXTERN BYTE *krmBufptr;       /* Buffer holding data read from comm port */
  315. KERMITEXTERN int *krmBuflen;       /* Length of data in buffer */
  316. KERMITEXTERN int *krmcid;       /* Comm port identifier */
  317. KERMITEXTERN HICON krmIcon;       /* Kermit icon */
  318.